import axios from "axios";
import {admin, crowd, publisher} from "@/store/pojo/Position";
import {IUser} from "@/store/pojo/IUser";
import router from "@/router";

const register = async (user: IUser) => {
    const position = user.position
    let url = "/api/";
    if (position == crowd) {
        url += crowd.toString();
    } else if (position == admin) {
        url += admin.toString();
    } else if (position == publisher) {
        url += publisher.toString();
    }
    url += "/register";

    const username = user.username;
    const password = user.password;
    const phone = user.phone;
    const email = user.email;


    return axios.post(url, {
        username,
        password,
        phone,
        email
    }).then(function (response) {
        //导航至登陆页面
        alert("即将跳转到登陆界面");
        router.push("/user/login");
    })
}

export default register;
